package com.mfangsoft.zhuangjialong.app.entryactivity.service.impl;


import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mfangsoft.zhuangjialong.app.entryactivity.mapper.BaseEntryActivityMapper;
import com.mfangsoft.zhuangjialong.app.entryactivity.model.BaseEntryActivity;
import com.mfangsoft.zhuangjialong.app.entryactivity.service.EntryActivityService;
import com.mfangsoft.zhuangjialong.common.model.Page;
import com.mfangsoft.zhuangjialong.common.utils.NoteUtils;
import com.mfangsoft.zhuangjialong.integration.order.model.OrderGift;




@Service
public class EntryActivityServiceimpl implements EntryActivityService {
	
	
	private static final Logger LOGGER = LoggerFactory.getLogger(EntryActivityServiceimpl.class); 
	
	
	@Autowired
	private BaseEntryActivityMapper baseEntryActivityMapper;

 
	@Override
	public void addEntryActivity(BaseEntryActivity baseEntryActivity) {
		baseEntryActivityMapper.addEntryActivity(baseEntryActivity);
		Integer shop_id = baseEntryActivity.getShop_id();
		Integer customer_id = baseEntryActivity.getCustomer_id();
//		if(shop_id!=null && customer_id!=null){
//			Map<String,Object> map=new HashMap<>();
//			map.put("shop_id", shop_id);
//			map.put("customer_id", customer_id);
//			Integer seller = baseEntryActivityMapper.selectSeller(map);
//			if(seller==0){
//				map.put("sellerId", null);
//				baseEntryActivityMapper.addCustomerSeller(map);
//			}
//		}
		Map<String, Object> map = baseEntryActivityMapper.selectCustomerNameAndSellerName(customer_id);
		if(map.get("sellerName")!=null && map.get("phone")!=null && map.get("customerName")!=null){
			try {
				NoteUtils.sendNode("SMS_121911530", map.get("phone").toString(), map.get("customerName").toString(), map.get("sellerName").toString());
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}


	@Override
	public Page<BaseEntryActivity> selectEntryActivity(Page<BaseEntryActivity> page) {
		 page.setData(baseEntryActivityMapper.selectEntryActivity(page));
		 page.setTotal(baseEntryActivityMapper.selectEntryActivityTotal());
		 	
		return page;
	}


	@Override
	public BaseEntryActivity selectSum(Integer activity_id) {
		// TODO Auto-generated method stub
		return baseEntryActivityMapper.selectSum(activity_id);
	}


	@Override
	public OrderGift selectOrderGift(Integer activity_id) {
		// TODO Auto-generated method stub
		return baseEntryActivityMapper.selectOrderGift(activity_id);
	}



	
	




}
